package com.woniu.woniu_bx.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniu.woniu_bx.pojo.GoodsComment;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
 * @Auther: Ayang
 * @Date: 2022/8/27 16:10
 * @Description:
 */

@Repository
public interface GoodsCommentMapper extends BaseMapper<GoodsComment> {

    /**
     * 根据商品 id，查询出订单 id，再根据订单 id 一一查出评论
     *
     * @param goodsId 商品 id
     * @return 商品评论集合
     */
    @Select("select c.*, c.order_id as orderId, c.user_id as userId,u.* " +
            "from bx_order o, bx_goods_comment c,bx_user u " +
            "where o.goods_id = #{goodsId} " +
            "and o.id = c.order_id and u.id=c.user_id")
    @Results(id = "commentMap",value = {
            @Result(column = "userId",property = "user",one = @One(select = "com.woniu.woniu_bx.mapper.UserMapper.getUserById"))
    })
    List<GoodsComment> getByGoodsId(Integer goodsId);
}
